﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Yz.Base;

namespace Yz.Core.Base
{
    public interface IDbAccess<TEntity> where TEntity : BaseEntity
    {
        ReturnCode Add(TEntity model, Expression<Func<TEntity, bool>> where = null);
        ReturnCode Add(TEntity model, List<Expression<Func<TEntity, bool>>> whereList);
        Task<ReturnCode> AddAsync(TEntity model, Expression<Func<TEntity, bool>> where = null);
        Task<ReturnCode> AddAsync(TEntity model, List<Expression<Func<TEntity, bool>>> whereList);
        TEntity AddGet(TEntity model, Expression<Func<TEntity, bool>> where = null);
        TEntity AddGet(TEntity model, List<Expression<Func<TEntity, bool>>> whereList);
        Task<TEntity> AddGetAsync(TEntity model, Expression<Func<TEntity, bool>> where = null);
        Task<TEntity> AddGetAsync(TEntity model, List<Expression<Func<TEntity, bool>>> whereList);
        int BatchAdd(List<TEntity> modelList);
        Task<int> BatchAddAsync(List<TEntity> modelList);
        int BatchDelete(Expression<Func<TEntity, bool>> where = null);
        Task<int> BatchDeleteAsync(Expression<Func<TEntity, bool>> where = null);
        int BatchUpdate(Expression<Func<TEntity, TEntity>> epsUpdate, Expression<Func<TEntity, bool>> where = null);
        int BatchUpdate(Expression<Func<TEntity, TEntity>> epsUpdate, List<TEntity> modelList);
        Task<int> BatchUpdateAsync(Expression<Func<TEntity, TEntity>> epsUpdate, List<TEntity> modelList);
        Task<int> BatchUpdateAsync(Expression<Func<TEntity, TEntity>> epsUpdate, Expression<Func<TEntity, bool>> where = null);
        ReturnCode Delete(Expression<Func<TEntity, bool>> where = null);
        Task<ReturnCode> DeleteAsync(Expression<Func<TEntity, bool>> where);
        ReturnList<T> GetListByPage<T>(Expression<Func<TEntity, bool>> where = null, ParaPage paraPage = null, List<ParaOrder<TEntity>> orders = null, bool hasTotal = true) where T : ViewModel;
        Task<ReturnList<T>> GetListByPageAsync<T>(Expression<Func<TEntity, bool>> where = null, ParaPage paraPage = null, List<ParaOrder<TEntity>> orders = null, bool hasTotal = true) where T : ViewModel;
        T GetModel<T>(Expression<Func<TEntity, bool>> where = null, List<ParaOrder<TEntity>> orders = null) where T : ViewModel;
        Task<T> GetModelAsync<T>(Expression<Func<TEntity, bool>> where = null, List<ParaOrder<TEntity>> orders = null) where T : ViewModel;
        int GetTotal(Expression<Func<TEntity, bool>> where = null);
        Task<int> GetTotalAsync(Expression<Func<TEntity, bool>> where = null);
        ReturnList<T> GetUnionListByPage<T>(List<Expression<Func<TEntity, bool>>> whereList, ParaPage paraPage = null, List<ParaOrder<TEntity>> orders = null, bool hasTotal = true, bool isOnly = true) where T : ViewModel;
        Task<ReturnList<T>> GetUnionListByPageAsync<T>(List<Expression<Func<TEntity, bool>>> whereList, ParaPage paraPage = null, List<ParaOrder<TEntity>> orders = null, bool hasTotal = true, bool isOnly = true) where T : ViewModel;
        int GetUnionTotal(List<Expression<Func<TEntity, bool>>> whereList);
        Task<int> GetUnionTotalAsync(List<Expression<Func<TEntity, bool>>> whereList);
        bool IsExist(Expression<Func<TEntity, bool>> where = null);
        Task<bool> IsExistAsync(Expression<Func<TEntity, bool>> where = null);
        ReturnCode Update(Expression<Func<TEntity, TEntity>> epsUpdate, Expression<Func<TEntity, bool>> where1 = null, Expression<Func<TEntity, bool>> where2 = null);
        ReturnCode Update(Expression<Func<TEntity, TEntity>> epsUpdate, List<Expression<Func<TEntity, bool>>> whereList2, Expression<Func<TEntity, bool>> where1 = null);
        Task<ReturnCode> UpdateAsync(Expression<Func<TEntity, TEntity>> epsUpdate, Expression<Func<TEntity, bool>> where1 = null, Expression<Func<TEntity, bool>> where2 = null);
        Task<ReturnCode> UpdateAsync(Expression<Func<TEntity, TEntity>> epsUpdate, List<Expression<Func<TEntity, bool>>> whereList2, Expression<Func<TEntity, bool>> where1 = null);
    }
}
